class Solution {
public:
    string multiply(string num1, string num2) {
        if (num1 == "0" || num2 == "0")
            return "0";
        vector<int >v1, v2;
        size_t size1 = num1.size();
        size_t size2 = num2.size();
        v1.reserve(size1);
        v2.reserve(size2);
        vector <int>v3(size1 + size2, 0);
        for (int x = size1 - 1; x >= 0; x--)
            v1.push_back(num1[x] - '0');
        for (int y = size2 - 1; y >= 0; y--)
            v2.push_back(num2[y] - '0');
        for (int i = 0; i < size1; i++)
            for (int j = 0; j < size2; j++)
                v3[i + j] += v1[i] * v2[j];
        int x = 0;
        for (size_t i = 0; i < v3.size(); i++)
        {
            v3[i] += x;
            x = v3[i] / 10;
            v3[i] = v3[i] % 10;
        }
        int size3 = v3.size() - 1;
        string tmp;
        if (!v3[size3])
        {
            size3--;
        }
        for (int x = size3; x >= 0; x--)
            tmp += (v3[x] + '0');
        return tmp;
    }
};
class Solution {
public:
    string addBinary(string a, string b) {
        int cur1 = a.size() - 1, cur2 = b.size() - 1;
        int count = 0;
        string s;
        while (count || cur1 >= 0 || cur2 >= 0)
        {
            if (cur1 >= 0) count += a[cur1] - '0';
            if (cur2 >= 0) count += b[cur2] - '0';
            s.insert(0, to_string(count % 2));
            count /= 2;
            cur1--, cur2--;
        }
        return s;
    }
};
